/*
 * c7_exercise6.cpp
 *
 *  Created on: Sep 2, 2013
 *      Author: cyper.yin
 */

#include <iostream>
using namespace std;

int Fill_array1(double arr[], int size);
void Show_array1(const double arr[], int size);
void Reverse_array1(double arr[], int size);
int main_c7e6(int argc, char **argv) {
	const int SIZE = 5;
	double arr[SIZE];

	//fill array
	int actual = Fill_array1(arr, SIZE);

	//show
	Show_array1(arr, actual);

	//reverse all but the first and the last elements
	Reverse_array1(arr + 1, actual - 2);

	//show again
	Show_array1(arr, actual);

	return 0;
}

int Fill_array1(double arr[], int size) {
	int i = 0;
	do {
		cout << "Enter a double:";
		if (!(cin >> arr[i])) {
			cin.clear();
			while (cin.get() != '\n') {
				continue;
			}
			break;
		}

	} while (++i < size);

	return i;
}

void Show_array1(const double arr[], int size) {
	cout << "[";
	for (int i = 0; i < size; i++) {
		cout << arr[i] << " ";
	}
	cout << "]" << endl;
}

void Reverse_array1(double arr[], int size) {
	for (int i = 0; i < size / 2; i++) {
		double temp = arr[i];
		int tail = size - i - 1;
		arr[i] = arr[tail];
		arr[tail] = temp;
	}

}
